package com.kyc.kycxkplaygame.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import com.kyc.kycxkplaygame.R;
import com.kyc.kycxkplaygame.util.SharedPreferencesUtils;

public class SettingActivity extends Activity {

    private ImageView setting_yinxiao;
    private ImageView setting_yinliang;
    private ImageView setting_shuoming;
    private ImageView wxpay_img;
    private ImageView aipay_img;
    private String payWay;

    private boolean wxpay = false;
    private boolean aipay = false;
    private boolean yx_open;
    private boolean yL_open;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setFinishOnTouchOutside(false);
        setContentView(R.layout.activity_setting);
        Window window = getWindow();
        WindowManager.LayoutParams layoutParams = window.getAttributes();
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
        layoutParams.alpha = 1f;
        window.setAttributes(layoutParams);

        setting_yinxiao = findViewById(R.id.setting_yinxiao);
        setting_yinliang = findViewById(R.id.setting_yinliang);
        setting_shuoming = findViewById(R.id.setting_shuoming);
        wxpay_img = findViewById(R.id.wxpay_img);
        aipay_img = findViewById(R.id.aipay_img);
        payWay = (String) SharedPreferencesUtils.getParam(this, "pay_way", "aipay");
        yx_open = (boolean) SharedPreferencesUtils.getParam(this, "yx_open", true);
        yL_open = (boolean) SharedPreferencesUtils.getParam(this, "yL_open", true);
        if(yx_open) {
            setting_yinxiao.setImageResource(R.drawable.yinxiao_open);
        }else {
            setting_yinxiao.setImageResource(R.drawable.setting_music_close);
        }

        if(yL_open) {
            setting_yinliang.setImageResource(R.drawable.yinliang_open);
        }else {
            setting_yinliang.setImageResource(R.drawable.setting_yinliang_close);
        }

        if(payWay.equals("wxpay")) {
            wxpay_img.setImageResource(R.drawable.wxpay_press);
            wxpay = true;
        }else {
            aipay_img.setImageResource(R.drawable.aipay_press);
            aipay = true;
        }
        findViewById(R.id.setting_activity_close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onBackPressed();
            }
        });

        setting_yinxiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(yx_open) {
                    setting_yinxiao.setImageResource(R.drawable.setting_music_close);
                }else {
                    setting_yinxiao.setImageResource(R.drawable.yinxiao_open);
                }
                yx_open = !yx_open;
                SharedPreferencesUtils.setParam(SettingActivity.this, "yx_open", yx_open);
            }
        });
        setting_yinliang.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(yL_open) {
                    setting_yinliang.setImageResource(R.drawable.setting_yinliang_close);
                }else {
                    setting_yinliang.setImageResource(R.drawable.yinliang_open);
                }
                yL_open = !yL_open;
                SharedPreferencesUtils.setParam(SettingActivity.this, "yL_open", yL_open);
            }
        });
        setting_shuoming.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
        wxpay_img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(wxpay && !aipay) {
                    wxpay_img.setImageResource(R.drawable.wxpay_normal);
                    aipay_img.setImageResource(R.drawable.aipay_press);
                    SharedPreferencesUtils.setParam(SettingActivity.this,"pay_way","aipay");
                }else {
                    wxpay_img.setImageResource(R.drawable.wxpay_press);
                    aipay_img.setImageResource(R.drawable.aipay_normal);
                    SharedPreferencesUtils.setParam(SettingActivity.this,"pay_way","wxpay");
                }
                wxpay =!wxpay;
                aipay = !aipay;
            }
        });
        aipay_img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(aipay && !wxpay) {
                    wxpay_img.setImageResource(R.drawable.wxpay_press);
                    aipay_img.setImageResource(R.drawable.aipay_normal);
                    SharedPreferencesUtils.setParam(SettingActivity.this,"pay_way","wxpay");
                }else {
                    wxpay_img.setImageResource(R.drawable.wxpay_normal);
                    aipay_img.setImageResource(R.drawable.aipay_press);
                    SharedPreferencesUtils.setParam(SettingActivity.this,"pay_way","aipay");
                }
                wxpay =!wxpay;
                aipay = !aipay;
            }
        });
    }

    @Override
    public void onBackPressed() {
        this.finish();
    }
}
